<template>
      <div class="brief-head-area page-gap">
            <div class="brief-banner-box">
                  <div class="banner-img-box relative flex" :style="{ 'height': propData.bannerHight + 'px' }">
                        <img :src="propData.pictureLink" alt="banner-img" />
                        <div>
                              <div class="constraint flex ali-center">
                                    <main>
                                          <p>{{ propData.majorHeading }}</p>
                                          <p>{{ propData.auxiliaryTitle }}</p>
                                    </main>
                              </div>
                        </div>
                  </div>
            </div>
            <el-affix>
                  <div class="mod-nav-co" v-if="propData.navHeadShow">
                        <div class="constraint">
                              <ul class="mod-co-ul">
                                    <li :class="['relative _item-li', { 'mod-nav-active': data.navIndex == index }]"
                                          v-for="(item, index) in headerList[propData.dataIndex].subList" :key="index">
                                          <a @click="getNavButtonChange(index, item.anchor_point)">{{ item.sub_text }}</a>
                                    </li>
                              </ul>
                        </div>
                  </div>
            </el-affix>
      </div>
</template>

<script lang="ts" setup>
import { onMounted, reactive } from 'vue'
import { headerList } from '@/config/assets.config'
import { useRoute } from 'vue-router'
const route = useRoute()
// props 数据传参
let propData = defineProps({
      // banner 图片地址 
      pictureLink: { default: '' },
      // banner 对应nav下标 
      dataIndex: { default: 0 },
      // 是否展示 nav辅助导航栏 
      navHeadShow: { default: true },
      // banner高度 
      bannerHight: { default: 420 },
      // banner 主标题文字
      majorHeading: { default: '' },
      // banner 辅助标题文字
      auxiliaryTitle: { default: '' }
})

// 响应式变量 
let data = reactive({
      navIndex: 0
})

onMounted(() => {
      if (location.hash) {
            let strChar = location.hash.split("#").join("")
            let strNumIndex = parseInt(strChar.charAt(strChar.length - 1)) - 1
            getNavButtonChange(strNumIndex, strChar)
      }
})

/**
 * Nav 辅助导航栏切换事件
 */
let getNavButtonChange = (e: number, anchorPoint: string) => {
      data.navIndex = e
      document.querySelector('#' + anchorPoint)?.scrollIntoView({
            behavior: "smooth",  // 平滑过渡
            block: "start"    // 上边框与视窗顶部平齐
      })
}
</script>

<style scoped>
.mod-co-ul {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
}

.mod-co-ul li {
    flex-shrink: 0;
}
.mod-co-ul a {
      line-height: 50px;
      height: 50px;
}
.banner-img-box img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.banner-img-box>div {
    position: absolute;
    top: 0;
    left: 0;
    color: #fff;
    font-style: italic;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, .5);
}

.banner-img-box p {
    font-size: 30px;
    letter-spacing: 4px;
    font-weight: 500;
    opacity: .9;
}

.banner-img-box p:last-child {
    font-size: 16px;
    font-style: normal;
}

.mod-nav-co {
    width: 100%;
    background-color: rgb(247, 247, 247);
    border-bottom: 1px solid rgb(230, 230, 230);
}

.mod-nav-co li {
    display: inline-block;
    margin-right: 56px;
}

.mod-nav-co li a {
    display: block;
    color: rgb(122, 122, 122);
}

.mod-nav-co .mod-nav-active a {
      color: #000;
      font-weight: bold;
}

.mod-nav-co li::after {
    content: "";
    width: 0;
    height: 3px;
    background-color: var(--main-color);
    display: block;
    position: absolute;
    bottom: 0;
    left: 0;
    visibility: hidden;
    transition: width linear .2s;
}

.mod-nav-co .mod-nav-active::after {
    visibility: visible;
    width: 100%;
}

.mod-nav-co .mod-nav-active {
    color: black;
}
</style>